package book.ch10;

import java.io.*;

public class MyTest3 {
    public static void main(String[] args) throws IOException {
        File file = new File("2.txt");


        long start = System.currentTimeMillis();
        read(file);
        long end = System.currentTimeMillis();

        long start2 = System.currentTimeMillis();
        bufferedRead(file);
        long end2 = System.currentTimeMillis();

        System.out.println("普通字节流耗时：" + (end - start) + " ms");
        System.out.println("缓冲字节流耗时：" + (end2 - start2) + " ms");

    }

    // 普通字节流
    public static void read(File file) throws IOException {
        FileReader os = new FileReader(file);
        char temp[]=new char[10];
        int n=-1;
        while((n=os.read(temp))!=-1){}

    }

    // 缓冲字节流
    public static void bufferedRead(File file) throws IOException {
        BufferedReader bi = new BufferedReader(new FileReader(file));
        char temp[]=new char[10];
        int n=-1;
        while((n=bi.read(temp))!=-1){}
    }
}
